// 点击勾选协议改变按钮状态
$("#weuiAgreeBank").change(function () {
    var agree = $("#weuiAgreeBank").is(":checked");
    var userApply = $("#userApply");
    if (agree){
        userApply.attr("class","weui-btn weui-btn_primary");
        userApply.attr("disabled",false);
    }else {
        userApply.attr("class","weui-btn weui-btn_disabled weui-btn_primary");
        userApply.attr("disabled",true);
    }
});
//获取开关的值
$('#isHasSecurity').on('click',function(){
    if($("#btnSecurity").val()=="0"){//判断和隐藏input值是否相同
        $("#btnSecurity").val("1");//设置隐藏input的值
        console.log("开关1当前状态："+$("#btnSecurity").val());
    }else{
        $("#btnSecurity").val("0");
        console.log("开关1当前状态："+$("#btnSecurity").val());
    }
})
$('#isHasFund').on('click',function(){
    if($("#btnhasFund").val()=="0"){
        $("#btnhasFund").val("1");
        console.log("开关1当前状态："+$("#btnhasFund").val());
    }else{
        $("#btnhasFund").val("0");
        console.log("开关1当前状态："+$("#btnhasFund").val());
    }
})
$('#isHasCar').on('click',function(){
    if($("#btnhasCar").val()=="0"){
        $("#btnhasCar").val("1");
        console.log("开关1当前状态："+$("#btnhasCar").val());
    }else{
        $("#btnhasCar").val("0");
        console.log("开关1当前状态："+$("#btnhasCar").val());
    }
})
$('#isHasHouse').on('click',function(){
    if($("#btnhasHouse").val()=="0"){
        $("#btnhasHouse").val("1");
        console.log("开关1当前状态："+$("#btnhasHouse").val());
    }else{
        $("#btnhasHouse").val("0");
        console.log("开关1当前状态："+$("#btnhasHouse").val());
    }
})
//点击下一步表单验证
$(document).ready(function () {
    $("#userApply").click(function () {
        var realName = $("#realName").val();
        var Names = $("#Name").val();
        var idCardNo = $("#idCardNo").val();
        var merId = $("#merId").val();
        var staffId = $("#staffId").val();
        if (!validInfo(realName,idCardNo,merId,Names)){
            return false;
        }

        var mobile;
        var mobileElm = $("#mobile");
        if (mobileElm.length > 0 ){
            mobile = mobileElm.val();
            if ($.isEmpty(mobile) || !mobile.match(/\d{11}/)){
                $.toast("请输入正确的手机号","forbidden");
                return false;
            }
        }

        var zmScore = $("#zmScore").val();
        if (!zmScore.match(/\d+/) || parseInt(zmScore) < 350 || parseInt(zmScore) > 900){
            $.toastForbidden("请输入正确的芝麻分");
            return false;
        }


        $.ajax(
            {

                url:'/loan/index/check',
                data:$('#form-user-info').serialize(),
                type : "post",    //请求类型
                dataType : "json",//返回的数据类型
                success:function (res) {
                    if(res.code===200){
                        location.href = res.url;
                    }else{
                        $.toast(res.msg,"forbidden");
                        return false;
                    }
                }
            }
        );
        return  false;
        //location.href="./creditAudit.html"
        function validInfo(realName,idCardNo,merId,Names) {

            if ($.isEmpty(realName)){
                $.toast("请输入姓名","forbidden");
                return false;
            }
            if ($.isEmpty(Names)){
                $.toast("请输入工号","forbidden");
                return false;
            }
            if ($.isEmpty(idCardNo)){
                $.toast("请输入身份证号","forbidden");
                return false;
            }
            return true;
        }
    })
})


